// 聊天消息类型
export interface ChatMessage {
  role: 'user' | 'assistant' | 'system';
  content: string;
  type: 'ai' | 'tool' | 'human';
  id: string;
}

// 聊天完成请求类型
export interface ChatCompletionRequest {
  messages: ChatMessage[];
  stream?: boolean;
  userId?: string;
  conversationId?: string;
  model?: string;
  temperature?: number;
  max_tokens?: number;
}

// 聊天完成响应中的选择项
export interface ChatCompletionChoice {
  index: number;
  message: ChatMessage;
  finish_reason?: string | null;
}

// 流式响应中的增量选择项
export interface ChatCompletionStreamChoice {
  index: number;
  delta: {
    role?: string;
    content?: string;
  };
  finish_reason?: string | null;
}

// 聊天完成响应类型
export interface ChatCompletionResponse {
  id: string;
  object: string;
  created: number;
  choices: ChatCompletionChoice[];
  system_fingerprint: string | null;
  usage?: {
    prompt_tokens: number;
    completion_tokens: number;
    total_tokens: number;
  };
}

// 流式聊天完成响应类型
export interface ChatCompletionStreamResponse {
  id: string;
  object: string;
  created: number;
  model: string;
  choices: ChatCompletionStreamChoice[];
}

// SQL查询请求类型
export interface SqlQueryRequest {
  query: string;
  userId?: string;
  conversationId?: string;
}

// SQL查询响应类型
export interface SqlQueryResponse {
  id: string;
  result: string;
  success: boolean;
  error: string | null;
  created: number;
}

// 健康检查响应类型
export interface HealthCheckResponse {
  status: string;
  service: string;
  graph_initialized: boolean;
  llm_initialized: boolean;
}

// API错误响应类型
export interface ApiErrorResponse {
  error: {
    message: string;
    type?: string;
    code?: string;
  };
}


// 认证相关类型
export interface LoginRequest {
  username: string;
  password: string;
}

export interface LoginResponse {
  success: boolean;
  message: string;
  userId?: string;
  token?: string;
}

export interface UserInfo {
  userId: string;
  username: string;
  created_at: string;
  last_login?: string;
}

export interface ValidateTokenRequest {
  token: string;
}

export interface ValidateTokenResponse {
  valid: boolean;
  userId?: string;
  message: string;
}

export interface AuthContextType {
  isAuthenticated: boolean;
  user: UserInfo | null;
  token: string | null;
  login: (username: string, password: string) => Promise<boolean>;
  logout: () => void;
  validateToken: () => Promise<boolean>;
  isLoading: boolean;
  error: string | null;
}